#include <iostream>
#include <queue>
#include <unordered_set>
#include <string>
using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;

    string target(n, '0');

    if (s == target)
    {
        cout << 0 << endl;
        return 0;
    }
    queue<pair<string, int>> q;
    unordered_set<string> visited;

    q.push({s, 0});
    visited.insert(s);

    while (!q.empty())
    {
        auto current = q.front();
        q.pop();

        string state = current.first;
        int steps = current.second;

        for (int i = 0; i < n - 1; ++i)
        {
            string next_state = state;
            next_state[i] = (next_state[i] == '0' ? '1' : '0');
            next_state[i + 1] = (next_state[i + 1] == '0' ? '1' : '0');

            if (next_state == target)
            {
                cout << steps + 1 << endl;
                return 0;
            }

            if (visited.find(next_state) == visited.end())
            {
                visited.insert(next_state);
                q.push({next_state, steps + 1});
            }
        }
    }

    cout << -1 << endl;
    return 0;
}